package com.longyue.ms.common.config.mvc;


import com.longyue.ms.common.interceptors.FormDataInterceptors;
import com.longyue.ms.common.interceptors.LoginInterceptors;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
    /**
     * 默认不拦截静态资源
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("/static/");
        registry.addResourceHandler("/css/**").addResourceLocations("/static/ms/css/");
        super.addResourceHandlers(registry);
    }

    /**
     * 注册springmvc 拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册表单重提交拦截器
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(new FormDataInterceptors());
        interceptorRegistration.addPathPatterns("/**");
        interceptorRegistration.excludePathPatterns("*.html");
        //注册登录校验拦截器
//        InterceptorRegistration loginInterceptor = registry.addInterceptor(new LoginInterceptors());
//        loginInterceptor.addPathPatterns("/**");
//        loginInterceptor.excludePathPatterns("*.html");
    }

}
